<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :fanhui="true">
			<block slot="content">历史记录</block>
		</cu-custom>
		<view class="cu-list menu-avatar">
			
			<view class="list-box" v-for="(item, index) in historyList" :key="index" :data-id="item.policyDetailsId" :data-date="item.publishTime" :data-tit="item.title" @tap="getContent">
				<view class="list-img">
					<image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.gtimg.com%2Fqd_house%2Fpics%2Fhv1%2F72%2F216%2F145%2F9483777.jpg&refer=http%3A%2F%2Fimg1.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1611990887&t=df43f7a52fcc771cb9fd66cfff49a226" mode="" class="img"></image>
				</view>
				<view class="list-text"  >
					<view class="list-title">{{ item.title }}</view>
					<view class="list-tag">
						<view class="tag-1 tag-inner">类型:{{ item.type }}</view>
						<view class="tag-2 tag-inner"><!-- 机关:{{ item.publishDepartment }} --></view>
						<view class="tag-3 tag-inner">时间:{{ item.publishTime }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token:'',
				userinfo:{},
				historyList:[],
				titleId: '',
				status: false,
				count:''
			}
		},
		onLoad() {
			this.gethistoryList()
		},
		methods: {
			gethistoryList(){
				let that = this
				let userinfo = uni.getStorageSync("userinfo")
				this.userinfo = userinfo
				var da = {
					userId: userinfo.id,
					tag: "历史记录"
				}
				this.http.getaction('/policy/articleCollectionExe/queryByUserId',da)
				.then(res => {
					this.historyList = res.data.result
				})
				.catch(err => {
					console.log(err)
				})

			},
			// 跳转到内容详情
			getContent(a) {
				this.titleId = a.currentTarget.dataset.id
				this.article()
				this.collecStu()
				this.lishi()
				// 获得文章收藏量
				var data = {
					articleId: this.titleId
				}
				this.http.getaction('/policy/articleCollectionExe/queryByArticleId',data)
				.then(res => {
					this.count = res.data.result.count
						var data = {
							titleId: this.titleId,
							publishTime: a.currentTarget.dataset.date,
							title: a.currentTarget.dataset.tit,
							count: this.count,
							status: this.status
						}
						this.navigate(this.titleId, a.currentTarget.dataset.date, a.currentTarget.dataset.tit, this.count, this.status)		
				})
				.catch(err => {
					console.log(err)
				})
			
			},
			// 跳转
			navigate(id, publishTime, title, count, status) {
				var data  = {
					articleId: id
				}
				this.http.getaction('/policy/clickCountExe/getClick', data)
				.then(res => {
					var clickCount = res.data.result.clickCount
					uni.navigateTo({
						url: '../article/article?id=' + id + '&count=' + count + '&clickCount=' + clickCount  +
							'&publishTime=' +
							publishTime + '&title=' + title + '&status=' + status
					})
				
				
				})
				.catch(err => {
					console.log(err)
				})
			},
			
			// 用户对此文章的收藏状态
			collecStu() {
				var data = {
					userId: this.userinfo.id,
					articleId: this.titleId
				}
				this.http.getaction('/policy/articleCollectionExe/getStatus',data)
				.then(res => {
					this.status = res.data.result.status
				})
				.catch(err => {
					console.log(err)
				})
					
			},
			
			// 用户历史记录
			lishi(){
				var  data = {
					userId: this.userinfo.id,
					articleId: this.titleId,
					tag:"历史记录"
				}
				this.http.postaction('/policy/articleCollectionExe/addHistory', data)
				.then(res => {
					
				})
				.catch(err => {
					console.log(err)
				})
			},
			
			// 文章点击量
			article() {
				var data = {
					articleId: this.titleId
				}
				this.http.putaction('/policy/clickCountExe/edit', data)
				.then(res => {
				
				})
				.catch(err => {
					console.log(err)
				})
			},
			
		}
	}
</script>

<style>
	.list-box {
		height: 150upx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.list-img {
		width: 23%;
		height: 140upx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.img {
		height: 90%;
		width: 90%;
	}

	.list-text {
		width: 75%;
		height: 140upx;
	}

	.list-title {
		width: 100%;
		height: 80upx;
		overflow:hidden;
		font-size: 32upx;
	}

	.list-tag {
		width: 100%;
		height: 50upx;
		margin-top: 6upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>
